<?php
/*
	[Destoon B2B System] Copyright (c) 2008-2011 Destoon.COM
	This is NOT a freeware, use is subject to license.txt
*/
defined('IN_DESTOON') or exit('Access Denied');
$catid or msg('请指定分类ID');
$table = $DT_PRE.'sxc';
$datalist = cache_read('sx.php','sell');
$menus = array (
    array('设置属性', '?file='.$file.'&action=add&catid='.$catid),
);
switch($action) {
	case 'add':
		if($submit) {
			//print_r($_POST);exit;
			$data = array();
			$str = '';
			$db->query("delete from $table where catid = $catid");
			if(is_array($pid))
			{
				foreach($pid as $k=>$v)
				{
					if(isset($v['sid']))
					{
						$data[$k] = $v;
						$str = implode(',',$v['sid']).',';
						$db->query("insert into $table (`name`,`sxid`,`sxids`,`catid`,`listorder`)values('".$datalist[$k]['name']."','".$v['cid']."','".$str."','".$catid."','0')");
					}	
				}
				//echo $str;
				//print_r($data);exit;
				cache_write('sx_'.$catid.'.php',$data,'sell');
			}
			dmsg('修改成功', '?file='.$file.'&action=add&catid='.$catid);
		} else {
			//$ids = cache_read('sx_'.$catid.'.php','sell');
			//print_r($ids);
			$ids = $arrs=array();
			$result = $db->query("select * from $table where catid = $catid order by listorder");
			while($r = $db->fetch_array($result))
			{
				$data[$r['sxid']] = $r;
			}
			if(is_array($data))
			{
				foreach($data as $k=>$v)
				{
					
					$arr = explode(',',substr($v['sxids'],0,-1));
					foreach($arr as $k1=>$v1)
					{
						$ids[$k]['sid'][$v1] = $v1;
					}
					$ids[$k]['tb'] = $v['tb'];
					$ids[$k]['cid'] = $v['sxid'];
				}
			}
			//print_r($ids);
			include tpl('sx_edit');
		}
	break;
	
	case 'order':
		
		dmsg('排序成功', $forward);
	break;
	case 'delete':
		dmsg('删除成功', '?file='.$file.'&catid='.$catid);
	break;
	default:
		$lists = $datalist;
		include tpl('sx_edit');
	break;
}
?>